﻿using System.Runtime.CompilerServices;
using System.Threading.Tasks;

namespace KingerRobot.MexicoSailunMDC.SpiService;
internal interface ITask
{

    //Task SyncScadaCrnTask();
    int SyncScadaCrnTask();
    /// <returns></returns>
    int UpdateTaskAndCmdTargetLoc(long taskId, long targetLoc);
    int UpdateTaskIsOutScannerByTaskNo(int taskNo);
    /// <summary>
    /// 出库线体任务 获取对象
    /// </summary>
    /// <param name="taskId"></param>
    /// <returns></returns>
    BizTaskBean GetOutTaskByTaskId(long taskId);
    /// <summary>
    /// 修改任务的当前设备以及当前库位
    /// </summary>
    /// <param name="taskId">任务ID</param>
    /// <param name="equipId">设备ID</param>
    /// <param name="locId">库位ID</param>
    /// <returns></returns>
    int UpdateTaskCurrentEquip(long taskId, long equipId, long locId);
    /// <summary>
    /// 修改任务类型
    /// </summary>
    /// <param name="taskId">任务ID</param>
    /// <param name="type">类型</param>
    void EditTaskType(long taskId, int type, long equipId);
    /// <summary>
    /// 创建出库输送线异常任务
    /// </summary>
    /// <param name="startLoc">扫描库位</param>
    /// <param name="skuId"></param>
    /// <param name="remark"></param>
    /// <returns></returns>
    long CreateOutAbnormalTask(long startLoc, long skuId, string remark, POWcsTask task, int taskNo = 0);
    /// <summary>
    /// 通过taskId获取任务信息
    /// </summary>
    /// <param name="taskId">任务ID</param>
    /// <returns>任务信息</returns>
    POWcsTask GetTaskByTaskId(long taskId);
    /// <summary>
    /// 通过任务获取目标位置
    /// </summary>
    /// <param name="taskId">任务ID</param>
    /// <returns></returns>
    long GetTargetIdByTaskId(long taskId);
    /// <summary>
    /// 通过订单查找任务
    /// </summary>
    /// <param name="summaryId"></param>
    /// <returns></returns>
    POWcsTask GetTaskBySummaryId(long summaryId);

    /// <summary>
    /// 修改经过硫化排虚拟位ID
    /// </summary>
    /// <param name="locId"></param>
    /// <param name="taskNo"></param>
    /// <returns></returns>
    int UpdateSpinScanId(long locId, long taskNo);
    /// <summary>
    /// 修改删除标识
    /// </summary>
    /// <param name="summaryId"></param>
    /// <returns></returns>
    int UpdateCallDelete(long summaryId);
    /// <summary>
    /// 通过taskId获取"已下发"状态任务
    /// </summary>
    /// <param name="taskId"></param>
    /// <returns></returns>
    POWcsTask GetExecutedTaskByTaskId(long taskId);


    /// <summary>
    /// 通过 skuId 获取任务
    /// </summary>
    /// <param name="skuId"></param>
    /// <returns></returns>
    POWcsTask GetTaskBySkuId(long skuId);

    long GetTaskIdBySkuId(long skuId);
    TaskCmdBean GetTaskCmdBeanBySkuId(long skuId);

    /// <summary>
    /// 通过类型查询任务
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    List<POWcsTask> GetTaskByType(int type);
    /// <summary>
    /// 获取所有生成请料单的任务
    /// </summary>
    /// <returns></returns>
    List<POWcsTask> GetHasSummaryTask();
    /// <summary>
    ///  获取所有出库/入库 未执行任务
    /// </summary>
    /// <returns></returns>
    List<POWcsTask> GetIOExecutableWcsTasksByType(EnumTaskType enumTaskType);
    /// <summary>
    /// 通过locId获取可执行任务s
    /// </summary>
    /// <param name="locId">位置ID</param>
    /// <returns>任务信息</returns>
    List<POWcsTask> GetExecutableTasksByLocId(long locId);
    /// <summary>
    /// 通过locId获取可执行任务TaskId
    /// </summary>
    /// <param name="locId">位置ID</param>
    /// <returns>任务信息</returns>
    long GetExecutableTaskIdkByLocId(long locId);
    /// <summary>
    /// 通过locId获取可执行任务s
    /// </summary>
    /// <param name="locId"></param>
    /// <returns></returns>
    POWcsTask GetExecutableTaskByLocId(long locId);
    /// <summary>
    /// 通过taskNo获取任务信息
    /// </summary>
    /// <param name="taskNo">任务号</param>
    /// <returns>任务信息</returns>
    POWcsTask GetTaskByTaskNo(int taskNo);
    /// <summary>
    /// 通过taskNo获取ems任务信息
    /// </summary>
    /// <param name="taskNo">任务号</param>
    /// <returns>任务信息</returns>
    POWcsTask GetEmsTaskByTaskNo(int taskNo);
    /// <summary>
    /// 通过taskNo获取"可下发"状态任务
    /// </summary>
    /// <param name="taskNo"></param>
    /// <returns></returns>
    POWcsTask GetExecutableTaskByTaskNo(int taskNo);
    /// <summary>
    /// 通过taskNo获取"已分配库位"状态任务
    /// </summary>
    /// <param name="taskNo"></param>
    /// <returns></returns>
    POWcsTask GetDistributionLocByTaskNo(int taskNo);
    /// <summary>
    /// 通过taskNo获取"执行入库"状态任务
    /// </summary>
    /// <param name="taskNo"></param>
    /// <returns></returns>
    POWcsTask GetExecutedByTaskNo(int taskNo);
    /// <summary>
    /// 通过taskNo获取"已下发"状态任务
    /// </summary>
    /// <param name="taskNo"></param>
    /// <returns></returns>
    POWcsTask GetExecutedTaskByTaskNo(int taskNo);
    /// <summary>
    /// 删除任务
    /// </summary>
    /// <param name="taskId">任务ID</param>
    /// <returns></returns>
    int DeleteTask(long taskId);
    /// <summary>
    /// 备份任务
    /// </summary>
    /// <param name="taskId"></param>
    /// <returns></returns>
    int BakTask(long taskId);
    /// <summary>
    /// 备份并删除任务和命令
    /// </summary>
    /// <param name="taskId"></param>
    /// <returns></returns>
    int BakAndDeleteTaskAndCmd(long taskId, string remarks = "", [CallerMemberNameAttribute] string MemberName = "", [CallerFilePathAttribute] string filePath = "", [CallerLineNumberAttribute] int callNumber = 0);
    /// <summary>
    /// 修改异常任务ID
    /// </summary>
    /// <param name="taskId"></param>
    /// <param name="abnormalId"></param>
    /// <param name="reamrk"></param>
    /// <returns></returns>
    int UpdateTaskAbnormal(long taskId, long abnormalId, string reamrk);
    /// <summary>
    /// 通过订单删除创建中的状态
    /// </summary>
    /// <param name="summaryId"></param>
    /// <returns></returns>
    int BakAndDeleteCreateTaskAndCmd(long summaryId);
    /// <summary>
    /// 所有正在执行小车
    /// </summary>
    /// <param name="emsId"></param>
    /// <param name="emsId2"></param>
    /// <returns></returns>
    List<POWcsTask> GetTaskByEmsId(long emsId, long emsId2);
    /// <summary>
    /// 备份并删除任务
    /// </summary>
    /// <param name="taskId"></param>
    /// <returns></returns>
    int BakAndDeleteTask(long taskId);

    /// <summary>
    /// 通过产品条码获取任务信息
    /// </summary>
    /// <param name="productCode">产品条码</param>
    /// <returns>任务信息（包含任务、任务命令）</returns>
    POWcsTask GetTaskByProductCode(string productCode);
    /// <summary>
    /// 通过产品条码获取任务信息(新入库)
    /// </summary>
    /// <param name="productCode"></param>
    /// <returns></returns>
    POWcsTask GetTaskByProductCodev2(string productCode);
    /// <summary>
    /// 通过备注查找入库任务
    /// </summary>
    /// <param name="remark"></param>
    /// <returns></returns>
    long GetInTaskIdByRemark(string remark);
    POWcsTask GetEmsTaskByProductCode(string productCode);
    /// <summary>
    /// 获取可执行
    /// </summary>
    /// <param name="productCode"></param>
    /// <returns></returns>
    POWcsTask GetTaskByExecuteProductCode(string productCode);
    /// <summary>
    /// 通过产品条码获取任务是否存在
    /// </summary>
    /// <param name="productCode">产品条码</param>
    /// <returns>true:存在；false:不存在</returns>
    bool HasTaskByProductCode(string productCode);

    /// <summary>
    /// 通过产品条码获取任务ID
    /// </summary>
    /// <param name="productCode">产品条码</param>
    /// <returns>任务ID</returns>
    long GetTaskIdByProductCode(string productCode);

    /// <summary>
    /// 通过目标位置获取所有任务
    /// </summary>
    /// <param name="targetLoc">目标位置Id</param>
    /// <returns>任务集合</returns>
    List<POWcsTask> GetAllTasksByTargetLoc(long targetLoc);

    /// <summary>
    /// 通过目标位置获取任务数量
    /// </summary>
    /// <param name="targetLoc">目标位置Id</param>
    /// <returns>任务数量</returns>
    int GetTaskCountByTargetLoc(long targetLoc);


    /// <summary>
    /// 通过目标位置获取是否有任务
    /// </summary>
    /// <param name="targetLoc">目标位置Id</param>
    /// <returns>是否有任务</returns>
    bool GetHasTaskByTargetLoc(long targetLoc);

    /// <summary>
    /// 创建任务
    /// </summary>
    /// <param name="taskDTO">任务数据传输对象</param>
    /// <returns></returns>
    POWcsTask CreateTask(TaskDTO taskDTO);

    /// <summary>
    /// 创建任务和命令
    /// </summary>
    /// <param name="taskDTO">任务数据传输对象</param>
    /// <returns>任务信息</returns>
    TaskInfoBean CreateTaskAndCmd(TaskDTO taskDTO);

    POWcsTaskCmd CreateEmsEmptyTaskAndCmd(long startLoc, long targetLoc, long startEquip);
    /// <summary>
    /// 创建任务和命令
    /// </summary>
    /// <param name="taskDTO">任务数据传输对象</param>
    /// <returns>任务信息</returns>
    TaskInfoBean CreateTaskAndCmdGroup(TaskDTO taskDTO);

    /// <summary>
    /// 出库放胎位汇总
    /// </summary>
    /// <returns></returns>
    List<TaskGroupCount> GetOutLocTaskGroup();

    /// <summary>
    /// 获取入库路线任务数量
    /// </summary>
    /// <param name="pOWcsAsrsNetInputs"></param>
    /// <param name="wcsAsrsCrnInputs"></param>
    List<CrnTaskCount> GetTaskInputCount(List<POWcsAsrsCrnInput> wcsAsrsCrnInputs);

    /// <summary>
    /// 创建异常返回Task ID
    /// </summary>
    /// <param name="startLoc">开始位置</param>
    /// <param name="skuId">prodsku</param>
    /// <param name="remark">备注</param>
    /// <returns>任务Id</returns>
    long CreateAbnormalResultTaskId(long startLoc, long skuId, string remark, int lineTaskNo);
    /// <summary>
    /// 创建异常返回Task ID——环形线
    /// </summary>
    /// <param name="startLoc">开始位置</param>
    /// <param name="skuId">prodsku</param>
    /// <param name="remark">备注</param>
    /// <returns>任务Id</returns>
    long CreateCircularAbnormalResultTaskId(long startLoc, long skuId, string remark, int lineTaskNo);
    /// <summary>
    /// 创建异常返回Task ID(出库二次扫描用)
    /// </summary>
    /// <param name="startLoc">开始位置</param>
    /// <param name="skuId">prodsku</param>
    /// <param name="remark">备注</param>
    /// <returns>任务Id</returns>
    long CreateOutAbnormalResultTaskId(long startLoc, long skuId, string remark, int lineTaskNo);

    /// <summary>
    /// 创建异常返回Cmd ID
    /// </summary>
    /// <param name="startLoc">开始位置</param>
    /// <param name="skuId">prodsku</param>
    /// <param name="remark">备注</param>
    long CreateAbnormalResultCmdId(long startLoc, long skuId, string remark, int taskNo, long equipId);

    /// <summary>
    /// 通过任务ID修改任务状态
    /// </summary>
    /// <param name="locId">当前位置</param>
    /// <param name="taskId">任务ID</param>
    /// <param name="status">状态</param>
    int UpdateTaskStatusByTaskId(long locId, long taskId, int status);
    /// <summary>
    /// 通过任务号修改
    /// </summary>
    /// <param name="locId"></param>
    /// <param name="taskNo"></param>
    /// <param name="status"></param>
    /// <returns></returns>
    int UpdateTaskStatusByTaskNo(long locId, int taskNo, int status, string remark = "");
    /// <summary>
    /// 集合修改状态
    /// </summary>
    /// <param name="taskIds"></param>
    /// <param name="status"></param>
    /// <returns></returns>
    int UpdateTaskAndCmdStatusByTaskIds(List<long> taskIds, int status);
    /// <summary>
    /// 通过id修改备注信息
    /// </summary>
    /// <param name="taskId"></param>
    /// <param name="remark"></param>
    /// <returns></returns>
    int UpdateTaskReamrkByTaskId(long taskId, string remark);

    /// <summary>
    /// 通过流水号修改备注信息
    /// </summary>
    /// <param name="taskNo"></param>
    /// <param name="remark"></param>
    /// <returns></returns>
    int UpdateTaskReamrkByTaskNo(int taskNo, string remark);

    int UpdateTaskDown(int taskNo, int down);

    /// <summary>
    /// 通过流水号修改条码与流水号的一致状态
    /// </summary>
    /// <param name="taskNo">任务流水号</param>
    /// <param name="errorCode">条码与流水号的一致状态 0正常 1不一致</param>
    /// <returns></returns>
    int UpdateErrorCodeByTaskNo(int taskNo, int errorCode);

    /// <summary>
    /// 通过流水号修改能否到目标位的状态
    /// </summary>
    /// <param name="taskNo"></param>
    /// <param name="targeCode">能否到目标位的状态 0正常 1无法到达</param>
    /// <returns></returns>
    int UpdateTargetCodeByTaskNo(int taskNo, int targeCode);


    /// <summary>
    /// 修改任务信息
    /// </summary>
    /// <param name="taskId"></param>
    /// <param name="pOWcsTask"></param>
    /// <returns></returns>
    int UpdateTask(long taskId, POWcsTask pOWcsTask);
    /// <summary>
    /// 修改任务的目标位
    /// </summary>
    /// <param name="taskId"></param>
    /// <param name="pOWcsTask"></param>
    /// <returns></returns>
    int UpdateTargetLocByTaskId(long taskId, POWcsTask pOWcsTask);

    /// <summary>
    /// 修改任务喷涂
    /// </summary>
    /// <param name="taskId"></param>
    /// <returns></returns>
    int UpdateTaskSpray(long taskId, int isSpray);
    /// <summary>
    /// 修改订单ID
    /// </summary>
    /// <param name="taskId"></param>
    /// <param name="maseterId"></param>
    /// <param name="summaryId"></param>
    /// <returns></returns>
    int UpdateTaskOrder(long taskId, long maseterId, long summaryId);
    /// <summary>
    /// 修改任务和命令状态
    /// </summary>
    /// <param name="locId">当前位置</param>
    /// <param name="taskId">任务ID</param>
    /// <param name="status">状态</param>
    int UpdateTaskAndCmdStatus(long locId, long taskId, int status);
    /// <summary>
    /// 修改线体任务
    /// </summary>
    /// <param name="taskId"></param>
    /// <param name="lineTaskNo"></param>
    /// <param name="skuId"></param>
    /// <param name="remark"></param>
    /// <returns></returns>
    int UpdateTaskLineTaskNo(long taskId, int lineTaskNo, long skuId, string remark);

    /// <summary>
    /// 目标位置任务汇总
    /// </summary>
    /// <returns>目标汇总数量</returns>
    List<TaskGroupCount> GetTargetLocTaskGroup();
    List<TaskGroupCount> GetTargetLocTaskGroupNoTaskIds(List<long> taskIds);
    /// <summary>
    /// 已执行目标位置任务汇总
    /// </summary>
    /// <returns>目标汇总数量</returns>
    List<TaskGroupCount> GetExecutedTargetLocTaskGroup();
    List<TaskGroupCount> GetExecutedTargetLocTaskGroupNoTaskIds(List<long> taskIds);
    /// <summary>
    /// 物料任务汇总
    /// </summary>
    /// <returns>物料汇总数量</returns>
    List<TaskGroupCount> GetMaterialTaskGroup();

    /// <summary>
    /// 开始任务汇总 [所有]
    /// </summary>
    /// <returns>开始放货位汇总数量</returns>
    List<TaskGroupCount> GetStartLocTaskGroup();
    /// <summary>
    /// 开始任务汇总 [未执行]
    /// </summary>
    /// <returns></returns>
    List<TaskGroupCount> GetStartLocExecutableTaskGroup();
    /// <summary>
    /// 开始位置获取任务
    /// </summary>
    /// <param name="startLoc"></param>
    /// <returns></returns>
    POWcsTask GetTaskByStartLoc(long startLoc);
    /// <summary>
    /// 创建出库单任务
    /// </summary>
    /// <param name="taskBean"></param>
    /// <param name="type"></param>
    /// <param name="status"></param>
    /// <returns></returns>
    TaskInfoBean CreateOutOrderTaskAndCmd(TaskBean taskBean, int type, int status);
    /// <summary>
    /// 修改入库任务并创建任务
    /// </summary>
    /// <param name="taskDTO">任务数据传输对象</param>
    /// <returns></returns>
    TaskInfoBean EditTaskAndCreateCmd(TaskDTO taskDTO);
    /// <summary>
    /// 通过设备查询是否有未完成任务
    /// </summary>
    /// <param name="equipId">设备Id</param>
    /// <returns>是否有任务</returns>
    bool IsTaskByEquipId(long equipId);
    /// <summary>
    /// 通过任务ID修改目标货位
    /// </summary>
    /// <param name="taskId">任务ID</param>
    /// <param name="targetLoc">目标货位</param>
    /// <returns></returns>
    int UpdateTaskTargetLoc(long taskId, long targetLoc, long masterId, long summaryId);
    /// <summary>
    /// 根据组号获取任务列表
    /// </summary>
    /// <param name="groupNo">组号</param>
    /// <returns></returns>
    List<POWcsTask> GetTasksByGroupNo(long groupNo);

    string GetPoductCodeByTaskNo(int taskNo);

    List<POWcsTask> GetTasksByGroupNoAndScanner(long groupNo, long scannerLoc);
    /// <summary>
    /// 获取ems取货位的下一条任务详情
    /// </summary>
    /// <param name="emsLoc">ems取料位</param>
    /// <param name="scannerLoc"></param>
    /// <param name="scannerTime"></param>
    /// <returns></returns>
    POWcsTask GetTasksByScannerAndTime(long emsLoc, long scannerLoc, DateTime scannerTime);
    /// <summary>
    /// 根据虚拟扫描获取当前ems取料位的排队任务总数
    /// </summary>
    /// <param name="emsLoc"></param>
    /// <param name="scannerLoc"></param>
    /// <returns></returns>
    List<POWcsTask> GetTasksByScannerAndEmsLoc(long emsLoc, long scannerLoc);
    /// <summary>
    /// 修改目标为
    /// </summary>
    /// <param name="taskId"></param>
    /// <param name="targetLoc"></param>
    /// <param name="remark"></param>
    /// <returns></returns>
    int UpdateTaskTargetLocRemark(long taskId, long targetLoc, string remark);
    /// <summary>
    /// 修改备注
    /// </summary>
    /// <param name="taskId"></param>
    /// <param name="remark"></param>
    /// <returns></returns>
    int UpdateTaskRemark(long taskId, string remark);
    /// <summary>
    /// 通过 taskId 获取物料ID
    /// </summary>
    /// <param name="taskIds"></param>
    /// <returns></returns>
    List<TaskMaterial> GetTaskMaterial(List<long?> taskIds);
    /// <summary>
    /// 通过 taskId 获取物料ID
    /// </summary>
    /// <param name="taskIds"></param>
    /// <returns></returns>
    List<TaskGroupCrnMaterialCount> GetTaskCrnGroupMaterial(List<PORcsEquipCrn> rcsCrns, List<POWcsAsrsCrnInput> wcsAsrsCrnInputs);
    /// <summary>
    /// 获取最后一条相关任务
    /// </summary>
    /// <param name="locId"></param>
    /// <param name="type"></param>
    /// <param name="materialId"></param>
    /// <returns></returns>
    (POWcsTask, List<long>) GetLastTaskByLocId(long locId, int type, long materialId);
    /// <summary>
    /// 修改任务扫描次数
    /// </summary>
    /// <param name="taskId">任务ID</param>
    /// <param name="count">更新后的扫描数</param>
    int UpdateTaskScansCount(long taskId, int count);
    /// <summary>
    /// 根据条码获取biz任务
    /// </summary>
    /// <param name="productCode"></param>
    /// <returns></returns>
    BizTaskBean GetTaskBeanByProductCode(string productCode);
    /// <summary>
    /// 开始位置获取信息
    /// </summary>
    /// <param name="startLoc"></param>
    /// <returns></returns>
    BizTaskBean GetTaskBeanByStartLoc(long startLoc);
    /// <summary>
    /// 通过扫描头获取所有可执行任务
    /// </summary>
    /// <param name="StartLoc"></param>
    /// <returns></returns>
    BizTaskBeanV2 GetTaskByExecuteStartLoc(long StartLoc);

    BizTaskBeanV2 GetTaskByCmdExecuteStartLoc(long StartLoc);

    List<BizTaskBeanV2> GetTaskByExecuteStartLocV3(long StartLoc);
    /// <summary>
    /// 人工删除任务
    /// </summary>
    /// <returns></returns>
    int DeleteOrCompleteHandTask();

    /// <summary>
    /// 根据WMS状态获取任务
    /// </summary>
    /// <param name="status"></param>
    /// <returns></returns>
    List<POWcsTask> GetAllTasksByWmsStatus(int status);
}

public class TaskCmdBean
{
    public long TaskId { get; set; }
    public int CmdStatus { get; set; }
    public long CmdTargetLoc { get; set; }
    public long CmdStartLoc { get; set; }
    public long SkuId { get; set; }

}
public class TaskInfoBean
{
    public POWcsTask POWcsTask { get; set; }
    public POWcsTaskCmd POWcsTaskCmd { get; set; }
}

public class TaskMaterial
{
    public long TaskId { get; set; }
    public long EquipId { get; set; }
    public int TaskNo { get; set; }
    public long SkuId { get; set; }
    public long MaterialId { get; set; }
    public int? GroupId { get; set; }
}

public class TaskGroupCount
{
    public int Count { get; set; }
    public long? LocId { get; set; }
}

public class TaskGroupCrnMaterialCount
{
    public int Count { get; set; }
    public long CrnId { get; set; }
    public long WarehouseId { get; set; }
    public long MaterialId { get; set; }
}

public class TaskBean
{
    public long? StartLoc { get; set; }
    public long? TaskTargetLoc { get; set; }
    public long? CmdTargetLoc { get; set; }
    public long? OutputLoc { get; set; }
    public CrnForkInfo Fork { get; set; }
    public int? Index { get; set; }
    public long? MasterId { get; set; }
    public long? SummaryId { get; set; }
    public int? GroupNo { get; set; }
    public int? StartTaskType { get; set; }
}
